package br.com.item.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.item.Item;
import br.com.item.ItemFaixada;

/**
 * Servlet implementation class ItemServlet
 */

public class ItemIncluir extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public ItemIncluir() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		PrintWriter out = response.getWriter();
		
		Item i = new Item();
		
		String descricao = request.getParameter("descricao");
		String precoCompra = request.getParameter("precoCompra");
		String precoVenda = request.getParameter("precoVenda");
		String quantidade = request.getParameter("quantidade");
		String marca = request.getParameter("marca");
		
		i.setDescricao(descricao);
		i.setValorCompra(Double.parseDouble(precoCompra));
		i.setPrecoVenda(Double.parseDouble(precoVenda));
		i.setMarca(marca);
		i.setQtdEstoque(Integer.parseInt(quantidade));		
		
		ItemFaixada item = ItemFaixada.getInstancia();
		
		
		item.adicionarItem(i);
		
		String destino = "ItemListar";
		
		response.sendRedirect (destino);
		
	}

}
